package org.hishen.example.web.admin.mall;

import javax.annotation.Resource;

import org.hishen.example.entity.mall.Category;
import org.hishen.example.service.admin.mall.CategoryService;
import org.hishenframework.data.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(CategoryController.PATH)
public class CategoryController {

	public static final String PATH = "/admin/mall/category";
	public static final String RELOAD = "redirect:" + PATH;
	
	@Resource
	private CategoryService categoryService;
	
	/**
	 * 
	 * @param page
	 * @return
	 */
	@RequestMapping
	public String list(Page page) {
		categoryService.list(page);
		return PATH + "/list";
	}
	
	/** 添加 */
	@RequestMapping("/create")
	public void create() {}
	
	@RequestMapping("/save")
	public String save(Category category) {
		categoryService.save(category);
		return RELOAD;
	}
	
	/**
	 * 
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping("/edit/{id}")
	public String edit(Model model, @PathVariable Integer id) {
		model.addAttribute(categoryService.get(id));
		return PATH + "/edit";
	}
	
	/***
	 * 
	 * @param category
	 * @return
	 */
	@RequestMapping("/update")
	public String update(Category category) {
		categoryService.update(category);
		return RELOAD;
	}
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	public String delete(Integer[] id) {
		categoryService.delete(id);
		return RELOAD;
	}
}
